//
//  Qb_BaseViewController.m
//  Cd_Qb
//
//  Created by mac on 2018/3/6.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "Qb_BaseViewController.h"
#import <objc/runtime.h>
@interface Qb_BaseViewController ()

@end

@implementation Qb_BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *backBtn = [[UIBarButtonItem alloc]initWithImage:[[UIImage imageNamed:@"Qb_Public_Back_W"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] style:UIBarButtonItemStylePlain target:self action:@selector(BackClick)];
    self.navigationItem.leftBarButtonItem = backBtn;
}
/*
 *  约束适配2
 */
-(void)AdaptationApp{
    NSArray *array = [self getAllProperties];
    NSDictionary *dic = [self properties_aps];
    NSMutableArray *ary = [NSMutableArray array];
    for (int i = 0; i<array.count; i++) {
        if ([dic[array[i]] isKindOfClass:[NSLayoutConstraint class]]) {
            [ary addObject:dic[array[i]]];
        }else{
        }
    }
    [self AdaptationWithConstraintAarray:ary];
}
/*
 *  约束适配1
 */
-(void)AdaptationWithConstraintAarray:(NSArray*)array{
    for (int i = 0; i<array.count; i++) {
        ((NSLayoutConstraint*)array[i]).constant = ((NSLayoutConstraint*)array[i]).constant*AdaptiveScale_W;
    }
}
/*
 *  取出所有属性名字
 */
-(NSArray *)getAllProperties
{
    u_int count;
    objc_property_t *properties  =class_copyPropertyList([self class], &count);
    NSMutableArray *propertiesArray = [NSMutableArray arrayWithCapacity:count];
    for (int i = 0; i<count; i++)
    {
        const char* propertyName =property_getName(properties[i]);
        [propertiesArray addObject: [NSString stringWithUTF8String: propertyName]];
    }
    free(properties);
    return propertiesArray;
}
/*
 *  找到约束属性
 */
- (NSDictionary *)properties_aps
{
    NSMutableDictionary *props = [NSMutableDictionary dictionary];
    unsigned int outCount, i;
    objc_property_t *properties = class_copyPropertyList([self class], &outCount);
    for (i = 0; i<outCount; i++)
    {
        objc_property_t property = properties[i];
        const char* char_f =property_getName(property);
        NSString *propertyName = [NSString stringWithUTF8String:char_f];
        id propertyValue = [self valueForKey:(NSString *)propertyName];
        if (propertyValue) [props setObject:propertyValue forKey:propertyName];
    }
    free(properties);
    return props;
}
/*
 *  全局返回
 */
- (void)BackClick
{
    [self.navigationController popViewControllerAnimated:YES];
}

@end
